/**
 * 
 */
package com.hrmsys.service.impl;

import java.util.List;

import net.sf.json.JSONArray;

import com.hrmsys.bean.PageBean;
import com.hrmsys.dao.LeaveDAO;
import com.hrmsys.enums.StaticValue;
import com.hrmsys.model.Leave;
import com.hrmsys.service.LeaveService;

/**
 * @author zhou
 *
 */
public class LeaveServiceImpl implements LeaveService {
	private LeaveDAO leaveDAO;

	@Override
	public String getAll(String start, String limit) {
		PageBean<Leave> findAll = leaveDAO.findAll(start,limit);
		String boonJson = JSONArray.fromObject(findAll.getRoot()).toString();
		return "{totalProperty:"+findAll.getTotalProperty()+",root:"+boonJson+"}";
	}

	@Override
	public String save(Leave dept) {
		boolean orUpdate = leaveDAO.saveOrUpdate(dept);
		if(orUpdate){
			return StaticValue.UPDATE_SUCCESS;
		}
		return StaticValue.UPDATE_FAILURE;
	}

	@Override
	public String delete(String ids) {
		String [] reIds = ids.split(",");
		if(leaveDAO.delete(reIds)){
			return StaticValue.DELETE_SUCCESS;
		}
		return StaticValue.DELETE_FAILURE;
	}

	@Override
	public String listById(String leaveId) {
		List<Leave> leave = leaveDAO.findById(leaveId);	
		return JSONArray.fromObject(leave).toString();
	}

	/**
	 * @return the leaveDAO
	 */
	public LeaveDAO getLeaveDAO() {
		return leaveDAO;
	}

	/**
	 * @param leaveDAO the leaveDAO to set
	 */
	public void setLeaveDAO(LeaveDAO leaveDAO) {
		this.leaveDAO = leaveDAO;
	}

	

}
